package zhangxin.third;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String[] color = {"草花", "方片", "红桃", "黑桃"};
        String[] number = {"K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2", "A"};
        List<String> deck = new ArrayList<>();
        for (String c : color) {
            for (String n : number) {
                deck.add(c + n);
            }
        }
        // 补充大王和小王
        deck.add("大王");
        deck.add("小王");
        // 洗牌
        Collections.shuffle(deck);
        Scanner scanner = new Scanner(System.in);
        System.out.print("\n请输入玩家数量：");
        int playerCount = scanner.nextInt();
        // 创建玩家列表
        List<List<String>> players = new ArrayList<>();
        for (int i = 0; i < playerCount; i++) {
            players.add(new ArrayList<>());
        }
        // 发牌
        int cardIndex = 0;
        while (cardIndex < deck.size()) {
            for (int i = 0; i < playerCount && cardIndex < deck.size(); i++) {
                players.get(i).add(deck.get(cardIndex));
                cardIndex++;
            }
        }
        // 显示每个玩家的牌
        System.out.println("\n=== 玩家牌面 ===");
        for (int i = 0; i < players.size(); i++) {
            System.out.println("玩家" + (i + 1) + "（共" + players.get(i).size() + "张牌）：");
            System.out.println(players.get(i));
            System.out.println();
        }

        scanner.close();
    }
}